// pages/godoor/godoor.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
      // types:['金属类','纸箱类','塑料类','旧衣类','旧家电','旧书籍'],
      bool1:false,bool2:false,bool3:false,
      bool4:false,bool5:false,bool6:false,
      background:'orange',
      address:'',


      // 输入框数据
      name:'',
      phone:'',
      types:[],

      obj:[
        {
          name:'金属类',
          bool:false
        },
        {
          name:'纸箱类',
          bool:false
        },
        {
          name:'塑料类',
          bool:false
        },
        {
          name:'旧衣类',
          bool:false
        },
        {
          name:'旧家电',
          bool:false
        },
        {
          name:'旧书籍',
          bool:false
        }

      ]

  },
  inputName: function(e) {
    console.log("e", e)
		this.setData({
			name: e.detail.value
    })
  },
  inputPhone: function(e) {
		this.setData({
			phone: e.detail.value
    })
  },
  inputAddress: function(e) {
		this.setData({
			address: e.detail.value
    })
  },
  
  submit(){
    let uniqueArray = [...new Set(this.data.types)];
    console.log(uniqueArray);
    console.log("name",this.data.name)
    wx.request({
      url: 'http://localhost:8080/goHome',
      method:'POST',
      data:{
        name:this.data.name,
        phone:this.data.phone,
        address:this.data.address,
        type:uniqueArray.join(",")
      }
    })
  },

  click(e){
    console.log(this.data.obj[index]);
    console.log("e",e.currentTarget.dataset.name)
    const arr = []

    arr.push(e.currentTarget.dataset.name)

    const index = e.currentTarget.dataset.index
    const flag = `obj[${index}].bool`
    // console.log(this.data.obj[index]);
    this.setData({
      [flag]: !this.data.obj[index].bool,
      types: [...this.data.types,...arr]
    })
    console.log("address",this.data.types);
  },


})